/*
 * LockQueue.h
 * A Locking queue (with mutex)
 * @author Hani shubin
 */
#ifndef LOCKQUEUE_
#define LOCKQUEUE_

#include <pthread.h>
#include "Node.h"

/**
 * Queue data.
 * 		head- the head of the queue
 * 		tail- the tail of the queue
 * 		states- an array of OpDesc for each thread
 * 		numOfThreads- number of threads that uses the queue
 * 		memoryManager- the MemoryManager of the queue
 */
typedef struct LockQueue_t{
	Node* head;
	Node* tail;
	pthread_mutex_t mutex;
}LockQueue;

/**
 * Get a LockQueue (c'tor).
 * Output: a new initialized LockQueue.
 */
inline LockQueue* getQueue(unsigned int numOfThreads);

/**
 * Delete a LockQueue (d'tor).
 * Input: a LockQueue to be deleted.
 * Assumption: 	This function must be called after all threads have finished
 * 				running.
 */
inline void deleteQueue(LockQueue* queue);

/**
 * Insert a value to the queue.
 * Input: 	queue- the queue where the value should be inserted
 * 			myTid- the tid of the inserting thread
 * 			value- the value to be inserted
 */
inline void enq(LockQueue* queue, long long myTid, int value);

/**
 * Remove a value from the queue.
 * Input: 	queue- the queue from where to take a value
 * Output: 	the value that was taken from the queue
 * 			or -1 if the queue is empty
 */
int deq(LockQueue* queue, long long myTid);

/**
 * Print queue nodes
 */
inline void printQueue(LockQueue* queue);

/**
 * Print queue size
 */
inline void printQueueSize(LockQueue* queue);


#endif /* LOCKQUEUE_ */
